package com.pretty.adminapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.templateresolver.ITemplateResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;

/**
 * 类描述：
 * 创建者：袁越
 * 创建日期：2017/3/31
 * 创建时间：22:00
 * Copyright:版权
 * © 2016-2020 上海金扳手科技信息股份有限公司 All rights reserved.
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@EnableJpaRepositories(basePackages = "com.pretty.adminapp.dao.**")
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 3600)
//@EnableResourceServer
public class AdminApp extends SpringBootServletInitializer {
    private static TemplateEngine templateEngine;
    private static ConfigurableApplicationContext applicationContext;
//    private Logger logger = LoggerFactory.getLogger(App.class);

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AdminApp.class);
    }

    @Bean
    public ITemplateResolver templateResolver() {
        ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix("classpath:/templates/");
        resolver.setSuffix(".html");
        resolver.setTemplateMode("HTML5");
        resolver.setCacheable(false);
        resolver.setOrder(0);
        templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(resolver);
        return resolver;
    }

    public static void main(String[] args) {

        applicationContext = SpringApplication.run(AdminApp.class, args);
    }

    public static TemplateEngine getTemplateEngine() {
        return templateEngine;
    }

    public static ConfigurableApplicationContext getApplicationContext() {
        return applicationContext;
    }
}
